package wang;

import org.assertj.core.util.Arrays;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;

/**
 * Created with IDEA
 * author:Yhk
 * Date:2019/3/7
 * Time:4:21 PM
 */
public class initproxy implements InvocationHandler {
    private Object target;

    /**
     * 绑定业务对象并返回一个代理类
     */
    public Object bind(Object target) {
        this.target = target;
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(), this);
    }


    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        Object result = null;
//        Object[][] rerarg = new Object[10][10];
        //调用真正的业务方法
        for (Object obj : args) {
            List<Object> list = Arrays.asList(obj);
            for (Object o : list) {
//                if (o instanceof java.lang.Integer) {
//                    args[0][1] = (Object) new Integer(0);
//                }
//                if (o instanceof java.lang.String) {
//                    args[0][1] = "";
//                }
//                if (o instanceof java.util.ArrayList) {
//                    args[0][2] = new ArrayList<String>();
//                }
                System.out.println(o);
            }

        }
        result = method.invoke(target, args);

        return result;
    }

}
